<?php

require_once('Zend/Controller/Plugin/Abstract.php');
require_once('Zend/Log.php');

class DoctrineProfile extends Zend_Controller_Plugin_Abstract
{
    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {
		global $Doctrine_Profiler;
		
		$logger = new Zend_Log();
		$writer = new Zend_Log_Writer_Firebug();
		$logger->addWriter($writer);
		
		$writer->setPriorityStyle(8, 'TABLE');
		$logger->addPriority('TABLE', 8);

		$time = 0;
		$queries = 0;
		 $queryLog[] = array('Query','Name', 'Elapsed Seconds');
		 foreach ($Doctrine_Profiler as $event) 
		 {
			$time += $event->getElapsedSecs();
			$queries++;
			$queryLog[] = array($event->getQuery(),$event->getName(),sprintf("%f", $event->getElapsedSecs()));
		}
		
		$table = array('Total time:'. $time .' - for '.$queries.' Operations',
            $queryLog
            );
			
			$logger->table($table);
		
		$Module = $request->getModuleName();
		$Controller = $request->getControllerName();
		$Action = $request->getActionName();
		
		
		//$logger->log($Module.'-'.$Controller.'-'.$Action.':'. endTimer(), Zend_Log::INFO);
    }
}